package edu.ubb.scrumster.model.repository;

import java.util.ArrayList;

import edu.ubb.scrumster.model.model.AbstractModel;
import edu.ubb.scrumster.model.model.Project;
import edu.ubb.scrumster.model.model.User;

public class ProjectRepository {

	public ProjectRepository() {
	}

	public ArrayList<Project> getAllProject() {
		ArrayList<Project> list = new ArrayList<Project>();
		for (AbstractModel d : DatabaseAccess.getInstance().getAll(DatabaseAccess.PROJECT)){
			list.add(getProjectById(((Project) d).getId()));
		}
		return list;
	}

	public void addProject(Project g) {
		DatabaseAccess.getInstance().addData(g);
	}

	public void updateProject(Project data) {
		DatabaseAccess.getInstance().updateData(data);
	}

	public void deleteProject(Project data) {
		DatabaseAccess.getInstance().deleteData(data);
	}

	public Project getProjectById(int id) {
		Project p = (Project)DatabaseAccess.getInstance().getDataById(id, DatabaseAccess.PROJECT);
		p.setOwner((User)DatabaseAccess.getInstance().getDataById(p.getOwner().getId(), DatabaseAccess.USER));
		return p;
	}
}
